package com.webkitlib.base;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.webkitlib.util.KLoger;
import com.webkitlib.util.KToast;

/**
 * 
 * 
 * @author 韩伟光
 * @version 1.0
 * @since 2016-1-18
 */
public abstract class BaseFragment extends Fragment {
    protected View mRootView;

    /**
     * 提示
     * 
     * @param message 提示内容
     */
    protected void ktoast(String message, int textColor, int backColor) {
        KToast.showToast(getActivity(), message, Toast.LENGTH_SHORT, textColor, backColor);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        KLoger.debug(this.getClass().getName() + "-->" + "onCreateView");
        if (null == mRootView) {
            mRootView = inflater.inflate(getLayoutId(), container, false);
        }
        return mRootView;
    }

    /**
     * 弹出Fragment栈
     */
    public void finish() {
        FragmentManager fragmentm = getFragmentManager();
        fragmentm.popBackStackImmediate();
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        KLoger.debug(this.getClass().getName() + "-->" + "onActivityCreated");
        afterCreate(savedInstanceState);
    }

    protected abstract int getLayoutId();

    protected abstract void afterCreate(Bundle savedInstanceState);



    /** ---------Created阶段：----------------- **/
    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        KLoger.debug(this.getClass().getName() + "-->" + "onAttach");
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        KLoger.debug(this.getClass().getName() + "-->" + "onCreate");
    }



    /** ---------onStart阶段：：----------------- **/
    @Override
    public void onStart() {
        super.onStart();
        KLoger.debug(this.getClass().getName() + "-->" + "onStart");
    }

    /** ---------onResumed阶段：：----------------- **/
    @Override
    public void onResume() {
        super.onResume();
        KLoger.debug(this.getClass().getName() + "-->" + "onResume");
    }

    /** ---------onPaused阶段：：----------------- **/
    @Override
    public void onPause() {
        super.onPause();
        KLoger.debug(this.getClass().getName() + "-->" + "onPause");
    }

    /** ---------onStop阶段：：----------------- **/
    @Override
    public void onStop() {
        super.onStop();
        KLoger.debug(this.getClass().getName() + "-->" + "onStop");
    }

    /** ---------onDestroy阶段：：----------------- **/
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        KLoger.debug(this.getClass().getName() + "-->" + "onDestroyView");
    }

    @Override
    public void onDetach() {
        super.onDetach();
        KLoger.debug(this.getClass().getName() + "-->" + "onDetach");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        KLoger.debug(this.getClass().getName() + "-->" + "onDestroy");
    }



}
